package bamin.com.bamindaijia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aiton.administrator.shane_library.shane.utils.Arith;
import com.aiton.administrator.shane_library.shane.widget.AnimCheckBox;

import java.util.HashMap;
import java.util.List;

import bamin.com.bamindaijia.R;
import bamin.com.bamindaijia.model.Order;

public class InvoiceOrdersAdapter extends BaseAdapter {
    private List<Order> mDatas;
    private HashMap<Integer, Order> isChecks;
    private LayoutInflater inflater;

    public InvoiceOrdersAdapter(Context context, List<Order> datas, HashMap<Integer, Order> isChecks) {

        inflater = LayoutInflater.from(context);

        mDatas = datas;
        this.isChecks = isChecks;
    }

    class ViewHolder {
        AnimCheckBox mCheck;
        TextView mTv_price;
        TextView mTv_start;
        TextView mTv_end;
        TextView mTv_time;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_invoice_order, null);
            holder.mCheck = (AnimCheckBox) convertView.findViewById(R.id.animCheckBox_order);
            holder.mTv_price = (TextView) convertView.findViewById(R.id.tv_price);
            holder.mTv_start = (TextView) convertView.findViewById(R.id.tv_start);
            holder.mTv_end = (TextView) convertView.findViewById(R.id.tv_end);
            holder.mTv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mCheck.setClickable(false);
        if (isChecks.get(position) != null) {
            holder.mCheck.setChecked(true, false);
        } else {
            holder.mCheck.setChecked(false, false);
        }
        Order resultsBean = mDatas.get(position);
        Double finalPrice = resultsBean.getFinalPrice();
        if(finalPrice == null){
            finalPrice = 0.00;
        }
        holder.mTv_price.setText("" + Arith.get2Double(finalPrice));
        holder.mTv_start.setText(resultsBean.getStartLocation());
        holder.mTv_end.setText(resultsBean.getEndLocation());
        holder.mTv_time.setText(resultsBean.getOrderTime());
        return convertView;
    }
}